'use strict'

import express from 'express'
import mongoose from 'mongoose'
import router from './router.js'
import fileUpload from 'express-fileupload'
import fs from 'fs'

const PORT = 5000
const DB_URL = fs.readFileSync('DB_URL.txt', 'utf8')
const app = express()

app.use(express.json())
app.use(express.static('static'))
app.use(express.static('static/pictures'))
app.use(fileUpload({}))
app.use('/api', router)


const startApp = async () => {
    try {
        await mongoose.connect(DB_URL, { useUnifiedTopology: true, useNewUrlParser: true, useFindAndModify: false })
        app.listen(PORT, () => {console.log(`server started on port ${PORT} OK`)})
    } catch (error) {
        console.log(error)
    }
}

startApp()